package com.hoozhi.education.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hoozhi.education.entity.EduGroup;
import com.hoozhi.education.service.EduGroupService;

@Controller
@RequestMapping(value="/group")
public class EduGroupAction {

	@Autowired
	public EduGroupService eduGroupService;
	
	@RequestMapping(value="/list")
	public String list(ModelMap modelMap){
		List<EduGroup> groupList = eduGroupService.getAllGroup();
		modelMap.put("groupList", groupList);
		return "group/list";
	}
	@RequestMapping(value="/showadd")
	public String showadd(ModelMap modelMap, EduGroup group){
		return "group/add";
	}
	@RequestMapping(value="/add")
	public String add(ModelMap modelMap, EduGroup group){
		System.out.println(group.getGroupname());
		eduGroupService.saveGroup(group);
		return list(modelMap);
	}
	@RequestMapping(value="/delete")
	public String delete(ModelMap modelMap, EduGroup group){
		System.out.println(group.getGid());
		eduGroupService.deleteGroupById(group.getGid());
		return list(modelMap);
	}
	@RequestMapping(value="/update")
	public String update(ModelMap modelMap, EduGroup group){
		eduGroupService.updateGroup(group);
		return list(modelMap);
	}
	@RequestMapping(value="/showupdate")
	public String showupdate(ModelMap modelMap, Integer gid){
		EduGroup group = eduGroupService.getGroupById(gid);
		modelMap.put("group", group);
		return "group/edit";
	}
}
